What is recursive-fs?
The recursive-fs npm package provides utilities for performing recursive file system operations such as copying and removing directories and their contents.
What are recursive-fs's main functionalities?
Recursive Copy
This feature allows you to recursively copy the contents of one directory to another. The code sample demonstrates how to use the `copy` method to copy all files and subdirectories from 'sourceDir' to 'destDir'.
const rfs = require('recursive-fs');
rfs.copy('sourceDir', 'destDir', function(err) {
if (err) {
console.error('Error during copy:', err);
} else {
console.log('Copy completed successfully');
}
});
Recursive Remove
This feature allows you to recursively remove a directory and all of its contents. The code sample demonstrates how to use the `remove` method to delete 'targetDir' and all files and subdirectories within it.
const rfs = require('recursive-fs');
rfs.remove('targetDir', function(err) {
if (err) {
console.error('Error during remove:', err);
} else {
console.log('Remove completed successfully');
}
});
Other packages similar to recursive-fs
fs-extra
fs-extra is a popular package that extends the native Node.js fs module with additional methods, including recursive file system operations. It provides similar functionality to recursive-fs, such as copying and removing directories recursively, but also includes many other useful file system utilities.
rimraf
rimraf is a package specifically designed for deep deletion of directories. It provides a simple and efficient way to recursively remove directories and their contents, similar to the remove functionality in recursive-fs.
ncp
ncp (Node Copy) is a package focused on copying files and directories. It supports recursive copying and provides similar functionality to the copy feature in recursive-fs. However, it is more specialized and does not include other file system operations.
recursive-fs
readdirr
var recursive = require('recursive-fs')
var path = require('path')
var directory = path.resolve(process.cwd(), process.argv[2])
recursive.readdirr(directory, function (err, dirs, files) {
if (err) {
console.log(err)
} else {
console.log(dirs)
console.log(files)
console.log('DONE!')
}
})
rmdirr
var recursive = require('recursive-fs')
var path = require('path')
var directory = path.resolve(process.cwd(), process.argv[2])
recursive.rmdirr(directory, function (err) {
if (err) {
console.log(err)
} else {
console.log('DONE!')
}
})
cpdirr
var recursive = require('recursive-fs')
var path = require('path')
var source = path.resolve(process.cwd(), process.argv[2])
var destination = path.resolve(process.cwd(), process.argv[3])
recursive.cpdirr(source, destination, function (err) {
if (err) {
console.log(err)
} else {
console.log('DONE!')
}
})
recursive-copy
npx recursive-copy 'path/to/source/directory' 'path/to/destination/directory'
recursive-delete
npx recursive-delete 'path/to/directory'